<!--页面主要内容-->
<main class="lyear-layout-content">

	<div class="container-fluid p-t-15">

		<div class="row">

			<div class="col-lg-12">
				<div class="card">

					<div class="card-toolbar d-flex flex-column flex-md-row">
						<div class="toolbar-btn-action">

							<a class="btn btn-primary" href="{:url('admin/product/type')}"><i class="mdi mdi-check m-r-5"></i>返回</a>
							
						</div>
						
					</div>

					<ul class="nav nav-tabs page-tabs pt-2 pl-3 pr-3">
						<li class="nav-item"> <a class="nav-link active" style="cursor: pointer;">产品分类添加</a> </li>
					</ul>
					<div class="tab-content">
						<div class="tab-pane active">

							<form method="post" name="edit-form" class="edit-form" enctype="multipart/form-data">
								<div class="form-group">
									<label for="">产品昵称</label>
									<input class="form-control" type="text" name="name" placeholder="请输入产品昵称">
								</div>

								<div class="form-group">
									<label for="">产品权重</label>
									<input class="form-control" type="number" name="weigh" placeholder="请输入产品权重">
								</div>

								<!-- 产品图片 -->
								<div class="form-group">
									<label for="cover">产品图片</label>
									<div class="input-group" style="display: block;">
										<input type="file" class="form-control" name="cover" id="cover" hidden="">
										<img id="img" class="img" width="200" src="/static/home/images/upload.png" />
										<div class="input-group-append">
											<button class="btn btn-default" type="button"
												onclick="upload()">上传图片</button>
										</div>
									</div>
								</div>

								<div class="form-group">
									<button type="submit" class="btn btn-primary m-r-5">确 定</button>
									<!-- <button type="button" class="btn btn-default"
                                        onclick="javascript:history.back(-1);return false;">返 回</button> -->
								</div>
							</form>

						</div>
					</div>

				</div>
			</div>

		</div>

	</div>

</main>
<!--End 页面主要内容-->
<script>
	// 图片预览函数
	function GetObjectURL(file) {
		// createObjectURL  给一个文件对象 可以提取出一个url本地地址出来
		var url = null;

		//判断是否为IE浏览器还是google还是其他浏览器
		if (window.createObjectURL != undefined) {
			url = window.createObjectURL(file)
		} else if (window.URL != undefined) {
			url = window.URL.createObjectURL(file)
		} else if (window.webkitURL != undefined) {
			url = window.webkitURL.createObjectURL(file)
		}

		return url
	}

	function upload() {
		// 点击拉起上传选择
		$('#cover').click()

		$('#cover').change(function() {
			let file = $('#cover')[0].files[0] ? $('#cover')[0].files[0] : {}

			let url = GetObjectURL(file)

			$('#img').attr('src', url)

		})

	}
</script>
